package cc.fs.study.pulltorefash;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cc.fs.study.R;

/**
 * Created by fostion on 6/16/16.
 */
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private List<String> mList;

    public MyAdapter(List<String> list){
        mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_city,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ItemViewHolder){
            ((ItemViewHolder) holder).bind(mList.get(position));
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder{
        TextView text;
        public ItemViewHolder(View itemView) {
            super(itemView);
            text = (TextView)itemView.findViewById(R.id.text);
        }

        public void bind(String city){
            text.setText(city);
        }
    }
}
